<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
    <style>
        thead tr th{text-align: center!important;}
        tr td{text-align: center!important;}
        .opeartion button{margin-bottom: 2px}
        .show-inner th{text-align: center!important;}
        .bold{font-weight: bold!important;}
        .layui-table th{font-weight: bold!important;}
        .name{color: #00a0e9}
    </style>
</head>
<body>
<div class="layui-fluid" >
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form action="/business/business" id="seachFrom" class="layui-form">
                    <div class="layui-card-body">
                        <%-- 查询条件设置 --%>
                        <div class="layui-container" style="width:100%">
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">商家名称：</div>
                                    <div class="layui-col-sm8">
                                        <input type="text" name="nickName" class="layui-input" value="${business.nickName}" placeholder="商家名称">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">营业执照：</div>
                                    <div class="layui-col-sm8">
                                        <input type="text" name="licenseCode" class="layui-input" value="${business.licenseCode}" placeholder="营业执照号">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">联系电话：</div>
                                    <div class="layui-col-sm8">
                                        <input type="text" name="phone" class="layui-input" value="${business.phone}" placeholder="商家联系电话">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">商家编号：</div>
                                    <div class="layui-col-sm8">
                                        <input type="text" name="businessCode" class="layui-input" value="${business.businessCode}" placeholder="商家编码">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md12">&nbsp;</div>
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">省份：</div>
                                    <div class="layui-col-md7">
                                        <select name="proId" class="address" data-flag="1">
                                            <option value="">请选择</option>
                                            <c:forEach items="${proAddrList}" var="sup">
                                                <option value="${sup.id}" ${sup.id==business.proId?'selected':''} >${sup.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">市区：</div>
                                    <div class="layui-col-sm7">
                                        <select name="cityId" class="city" data-flag="2">
                                            <option value="">请选择</option>
                                            <c:forEach items="${cityAddrList}" var="sup">
                                                <option value="${sup.id}" ${sup.id==business.cityId?'selected':''} >${sup.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">县/区域：</div>
                                    <div class="layui-col-sm8">
                                        <select name="areaId" class="area" data-flag="3">
                                            <option value="">请选择</option>
                                            <c:forEach items="${areaAddrList}" var="sup">
                                                <option value="${sup.id}" ${sup.id==business.areaId?'selected':''} >${sup.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            <div class="layui-col-md12">&nbsp;</div>
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">时间范围</div>
                                    <div class="layui-col-sm7">
                                        <input class="layui-input" name="queryTime" id="laydate-cn" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">审核状态：</div>
                                    <div class="layui-col-sm7">
                                        <select name="status">
                                            <option value="">请选择</option>
                                            <option value="1" ${business.status==1?'selected':''}>待审核</option>
                                            <option value="2" ${business.status==2?'selected':''}>已通过</option>
                                            <option value="3" ${business.status==3?'selected':''}>已驳回</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md2">
                                    <div class="layui-col-sm3">
                                        <button class="layui-btn layui-btn" type="submit">查询</button>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md12"><hr></div>
                        </div>
                        <%-- 数据展示 --%>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>范围 | 名称 | 状态</th>
                                <th>商家编号</th>
                                <th>店铺范围</th>
                                <th>店铺类型</th>
                                <th>经营行业</th>
                                <th>来源</th>
                                <th>联系电话</th>
                                <%--<th>店铺状态</th>--%>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${pageInfo.records}" var="l">
                                <tr>
                                    <td width="4%">${l.id}</td>
                                    <td width="20%">
                                        <table class="show-inner">
                                            <c:if test="${l.nickNameOn != null && l.nickNameOn != ''}">
                                                <tr>
                                                    <th width="5%" class="bold">线上</th>
                                                    <th width="10%" class="name">${l.nickNameOn}</th>
                                                    <th width="6%">
                                                        <c:if test="${l.status==1}">
                                                            <span class="layui-badge-rim">待审核</span><br>
                                                        </c:if>
                                                        <c:if test="${l.status==2}">
                                                            <span class="layui-badge layui-bg-green">通过</span><br>
                                                        </c:if>
                                                        <c:if test="${l.status==3}">
                                                            <span class="layui-badge">驳回</span><br>
                                                        </c:if>
                                                    </th>
                                                </tr>
                                            </c:if>
                                            <c:if test="${l.nickName != null && l.nickName != ''}">
                                                <tr>
                                                    <th width="5%" class="bold">线下</th>
                                                    <th width="10%" class="name">${l.nickName}</th>
                                                    <th width="6%">
                                                        <c:if test="${l.offlineStatus==1}">
                                                            <span class="layui-badge-rim">待审核</span><br>
                                                        </c:if>
                                                        <c:if test="${l.offlineStatus==2}">
                                                            <span class="layui-badge layui-bg-green">通过</span><br>
                                                        </c:if>
                                                        <c:if test="${l.offlineStatus==3}">
                                                            <span class="layui-badge">驳回</span><br>
                                                        </c:if>
                                                    </th>
                                                </tr>
                                            </c:if>
                                        </table>
                                    </td>
                                    <td width="5%">${l.businessCode}</td>
                                    <td width="5%">
                                        <c:if test="${l.onOff==0}">线上</c:if>
                                        <c:if test="${l.onOff==1}">线下</c:if>
                                        <c:if test="${l.onOff==2}">全部</c:if>
                                    </td>
                                    <td width="5%">${l.businessTypeName}</td>
                                    <td width="5%">${l.industryName}</td>
                                    <td width="6%">${l.fromName}</td>
                                    <td width="10%">${l.phone}</td>
                                    <%--<td width="5%">
                                        <c:if test="${l.open==1}">
                                            <span class="btn btn-success-outline radius size-MINI">正常</span>
                                        </c:if>
                                        <c:if test="${l.open==0}">
                                            <span class="btn btn-danger-outline radius size-MINI">关店</span>
                                        </c:if>
                                    </td>--%>
                                    <td width="11%"><fmt:formatDate value="${l.createtime}" pattern="yyyy-MM-dd HH:mm"></fmt:formatDate></td>
                                    <td width="5%" class="opeartion">
                                        <c:if test="${l.lookProduct}">
                                            <button data-id="${l.id}" data-type="toProduct" type="button"
                                                    class="layui-btn layui-btn-normal layui-btn-sm  toProduct">商品列表</button><br>
                                        </c:if>
                                        <c:if test="${l.guarantee==2}">
                                            <button data-id="${l.id}" data-guarantee="1" data-type="guarantee" type="button"
                                                    class="layui-btn layui-btn-primary layui-btn-sm  red guarantee">消费者保证权益</button><br>
                                        </c:if>
                                        <c:if test="${l.status==1}">
                                            <a data-id="${l.id}" data-apply="2" data-type="applyThis" class="layui-btn layui-btn-sm applyThis">通过</a><br>
                                            <a data-id="${l.id}" data-apply="3" data-type="applyThis" class="layui-btn layui-btn-sm layui-btn-warm applyThis"
                                               style="margin-top: 5px">驳回</a><br>
                                        </c:if>
                                        <c:if test="${l.offlineStatus==1}">
                                            <a data-id="${l.id}" data-offline="2" data-type="offlineApply" class="layui-btn layui-btn-sm offlineApply">通过</a><br>
                                            <a data-id="${l.id}" data-offline="3" data-type="offlineApply" class="layui-btn layui-btn-sm layui-btn-warm offlineApply"
                                               style="margin-top: 5px">驳回</a><br>
                                        </c:if>
                                        <button data-id="${l.id}" data-type="editThis" type="button" class="layui-btn
                                                        layui-btn-warm layui-btn-sm  editThis">编辑商家资料</button><br>
                                        <button data-id="${l.id}" data-flag="2" data-type="updatePassword" type="button"
                                                class="layui-btn layui-btn-primary layui-btn-sm  updatePassword">重置交易密码</button><br>
                                        <button data-id="${l.id}" data-flag="1" data-type="updatePassword" type="button"
                                                class="layui-btn layui-btn-primary layui-btn-sm  updatePassword">重置登录密码</button><br>
                                        <c:if test="${l.BType != 1}">
                                            <button data-id="${l.id}" data-type="delThis" type="button" style="margin-top: 5px"
                                                    class="layui-btn layui-btn-danger layui-btn-sm  delThis">删除商家</button><br>
                                        </c:if>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        <div class="test-table-reload-btn" style="margin-top: 10px;">
                            <%@include file="../paging.jsp" %>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form', 'laydate'], function(){
        var $ = layui.$,layer = layui.layer,form = layui.form,element = layui.element,laydate = layui.laydate;
        form.render('select');
        element.render();

        var today = new Date();
        var last = today.getFullYear() + "-" + today.getMonth() + "-" +today.getDate();
        today = today.getFullYear() + "-" + (today.getMonth()+1) + "-" +today.getDate();
        laydate.render({
            elem: '#laydate-cn',
            range:'~',
            max:today
        });

        form.on('select',function(data){
            var dom = data.elem;
            var flag = $(dom).data('flag');
            var id = data.value;
            if(flag===1 || flag===2){
                $.ajax({
                    url: "/sys/queryAddressNoPage",
                    data: {"pid":id},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data.data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>';
                        });
                        if(flag===1){
                            $(".city").html("");
                            $(".area").html("");
                            $(".city").append(html);
                        }else if(flag===2){
                            $(".area").html("");
                            $(".area").append(html);
                        }
                        form.render("select");
                    }
                });
            }
        });

        var active = {
            //新增 / 编辑
            editThis:function (id) {
                if(id != ""){
                    window.location.href = "/business/businessEdit?id="+id;
                }else{
                    window.location.href = "/business/businessAdd";
                }
            },
            //审核
            applyThis:function(id,status,url){
                $.ajax({
                    url: url,
                    data: {'id': id, "status": status},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.status) {
                            layer.msg(data.desc);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000)
                        } else {
                            layer.msg(data.desc);
                        }
                    }
                })
            },
            //驳回申请
            reject:function(id,status,url){
                layer.prompt({title: '驳回商家申请', formType: 2}, function(text, index){
                    $.ajax({
                        url: url,
                        data: {'id': id, "status": status,"rejRemark":text},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.close(index);
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    });
                });
            },
            //线下驳回申请
            rejectOffline:function(id,offlineStatus,url){
                layer.prompt({title: '驳回商家申请', formType: 2}, function(text, index){
                    $.ajax({
                        url: url,
                        data: {'id': id, "offlineStatus": offlineStatus,"rejRemark":text},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.close(index);
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    });
                });
            },
            //关闭开启
            updateThis:function (id,open,url) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: url,
                        data: {'id': id, "open": open},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    })
                });
            },
            //重置密码
            updatePassword:function (id,flag,url) {
                layer.confirm("确定要重置吗？重置后密码为'888888'", function(){
                    $.ajax({
                        url: url,
                        data: {'id': id, "type": flag},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    })
                });
            },
            //消费者权益
            guarantee:function (id,guarantee,url) {
                layer.confirm("确定设置消费者权益吗？", function(){
                    $.ajax({
                        url: url,
                        data: {'id': id, "guarantee": guarantee},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    })
                });
            },
            offlineApply:function(id,offlineStatus,url){
                $.ajax({
                    url: url,
                    data: {'id': id, "offlineStatus": offlineStatus},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.status) {
                            layer.msg(data.desc);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000)
                        } else {
                            layer.msg(data.desc);
                        }
                    }
                })
            },
            toProduct:function(id){
                window.location.href = "/product/product?bid="+id;
            },
            delThis:function (id,msg) {
                layer.confirm(msg, function(){
                    $.ajax({
                        url: '/business/deleteBusinessById',
                        data: {"id": id},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc,{icon:1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc,{icon:2});
                            }
                        }
                    });
                });
            }
        };

        //定义新增与编辑的type
        var editType = "editThis";
        $('.editThis').on('click', function(){
            var id = $(this).data('id');
            active[editType] && active[editType].call(this,id);
        });
        $('.addThis').on('click', function(){
            var id = $(this).data('id');
            active[editType] && active[editType].call(this,id);
        });
        //审核事件触发
        $('.applyThis').on('click',function () {
            var applyType = $(this).data('type');
            var rejectType = "reject";
            var id = $(this).data('id');
            var status = $(this).data('apply');
            var url = "/business/handleBusinessApplyStatus";
            if(status === 2){
                active[applyType] && active[applyType].call(this,id,status,url);
            }else if(status===3){
                active[rejectType] && active[rejectType].call(this,id,status,url);
            }
        });
        //开启/关闭事件触发
        $('.updateThis').on('click',function () {
            var updateType = $(this).data('type');
            var id = $(this).data('id');
            var open = $(this).data('open');
            var url = "/business/handleBusinessApplyStatus";
            active[updateType] && active[updateType].call(this,id,open,url);
        });
        //重置密码事件触发
        $('.updatePassword').on('click',function () {
            var passwordType = $(this).data('type');
            var id = $(this).data('id');
            var flag = $(this).data('flag');
            var url = "/business/handleResetBusinessPassword";
            active[passwordType] && active[passwordType].call(this,id,flag,url);
        });
        //消费者保证权益事件触发
        $('.guarantee').on('click',function () {
            var type = $(this).data('type');
            var guarantee = $(this).data('guarantee');
            var id = $(this).data('id');
            var url = "/business/handleSetGuarantee";
            active[type] && active[type].call(this,id,guarantee,url);
        });
        //线下审核
        $(".offlineApply").on("click",function () {
            var type = $(this).data('type');
            var rejectType = "rejectOffline";
            var id = $(this).data('id');
            var offlineStatus = $(this).data('offline');
            var url = "/business/handleBusinessApplyStatus";
            if(offlineStatus === 2){
                active[type] && active[type].call(this,id,offlineStatus,url);
            }else if(offlineStatus===3){
                active[rejectType] && active[rejectType].call(this,id,offlineStatus,url);
            }
        });
        //商品列表事件触发
        $(".toProduct").on('click',function () {
            var type = $(this).data('type');
            var id = $(this).data('id');
            active[type] && active[type].call(this,id);
        });
        //删除商家信息事件触发
        $(".delThis").on('click',function () {
            var id = $(this).data('id');
            var type = $(this).data('type');
            var msg = '<span style="color:red;font-weight: bold;font-size:16px">该操作不可逆！确定删除该资料吗？</span><br>';
            msg += '该操作将删除以下信息：<br><hr>';
            msg += '1.商家<span style="color:red;font-weight:bold;">账户</span>信息；<br>';
            msg += '2.商家<span style="color:red;font-weight:bold;">登录</span>信息；<br>';
            msg += '3.商家<span style="color:red;font-weight:bold;">申请</span>信息；<br>';
            active[type] && active[type].call(this,id,msg);
        })
    });
</script>
</body>
</html>